var flags = {
	"ONEWAY_MESSAGE_FLAG" : 1,
	"TWOWAY_MESSAGE_FLAG" : 2,
	"MY_POST_FLAG" : 4,
	"FRIEND_POST_FLAG" : 8,
	"MY_COMMENT_ON_STATUS_FLAG" : 16,
	"MY_COMMENT_ON_LINK_FLAG" : 32,
	"MY_COMMENT_ON_NOTE_FLAG" : 64,
	"MY_COMMENT_ON_PHOTO_FLAG" : 128,
	"FRIEND_COMMENT_ON_STATUS_FLAG" : 256,
	"FRIEND_COMMENT_ON_LINK_FLAG" : 512,
	"FRIEND_COMMENT_ON_NOTE_FLAG" : 1024,
	"FRIEND_COMMENT_ON_PHOTO_FLAG" : 2048,
	"MY_LIKE_ON_STATUS_FLAG" : 4096,
	"MY_LIKE_ON_LINK_FLAG" : 8192,
	"MY_LIKE_ON_NOTE_FLAG" : 16384,
	"MY_LIKE_ON_PHOTO_FLAG" : 32768,
	"FRIEND_LIKE_ON_STATUS_FLAG" : 65536,
	"FRIEND_LIKE_ON_LINK_FLAG" : 131072,
	"FRIEND_LIKE_ON_NOTE_FLAG" : 262144,
	"FRIEND_LIKE_ON_PHOTO_FLAG" : 524288
};

var mockup_all_data_without_error = {
	    "data": [
	             {
	                 "fId" : "100000416787478",
	                 "count": {
	                     "TWOWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_POST_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "14",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "3",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "8",
	                     "FRIEND_LIKE_ON_NOTE_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "612139051",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "16",
	                     "TWOWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_POST_FLAG" : "3",
	                     "MY_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "2",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000525262538",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "TWOWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "11",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "6",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "2",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "509836156",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "18",
	                     "TWOWAY_MESSAGE_FLAG" : "3",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000526102422",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "4",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "10",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "5"
	                 }
	             },
	             {
	                 "fId" : "1559108118",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "19"
	                 }
	             },
	             {
	                 "fId" : "100001871979183",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "10",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "3",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "2",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001623437056",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "MY_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "6",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1",
	                     "MY_LIKE_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "2",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_NOTE_FLAG" : "3"
	                 }
	             },
	             {
	                 "fId" : "100001197734599",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "16",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000560912448",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "6",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "3",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_NOTE_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "1382591304",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "9",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "1468604886",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "TWOWAY_MESSAGE_FLAG" : "8",
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "100001736213735",
	                 "count": {
	                     "TWOWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "5",
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "2",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000767659366",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "3",
	                     "TWOWAY_MESSAGE_FLAG" : "4",
	                     "FRIEND_POST_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001442696712",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "MY_COMMENT_ON_LINK_FLAG" : "1",
	                     "MY_COMMENT_ON_NOTE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "4",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1",
	                     "MY_LIKE_ON_LINK_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "711806955",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "5",
	                     "TWOWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1452136143",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "2",
	                     "TWOWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_POST_FLAG" : "3",
	                     "MY_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "100001496104711",
	                 "count": {
	                     "TWOWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "5",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_NOTE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001278657897",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "4",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "703412893",
	                 "count": {
	                     "MY_COMMENT_ON_NOTE_FLAG" : "1",
	                     "MY_COMMENT_ON_PHOTO_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "3"
	                 }
	             },
	             {
	                 "fId" : "100001660120678",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "5"
	                 }
	             },
	             {
	                 "fId" : "720480184",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_POST_FLAG" : "1",
	                     "MY_LIKE_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "732486215",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "4"
	                 }
	             },
	             {
	                 "fId" : "645061280",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "TWOWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001324002549",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "3",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "573168545",
	                 "count": {
	                     "MY_COMMENT_ON_PHOTO_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "100001057185849",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "534124579",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "572356495",
	                 "count": {
	                     "TWOWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001875630715",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1",
	                     "FRIEND_LIKE_ON_STATUS_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1676325929",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "555926326",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "2",
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "15720738",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "2",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "607711964",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "2"
	                 }
	             },
	             {
	                 "fId" : "100001770838666",
	                 "count": {
	                     "FRIEND_COMMENT_ON_NOTE_FLAG" : "1",
	                     "FRIEND_LIKE_ON_NOTE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1128757552",
	                 "count": {
	                     "FRIEND_COMMENT_ON_LINK_FLAG" : "1",
	                     "FRIEND_LIKE_ON_LINK_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001963907431",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1535994324",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "MY_COMMENT_ON_PHOTO_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000591117659",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1637340897",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001297801606",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1847145997",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_COMMENT_ON_PHOTO_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1356805212",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "550118413",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1",
	                     "TWOWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "643085324",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "591658379",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000568852321",
	                 "count": {
	                     "TWOWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000243514929",
	                 "count": {
	                     "MY_LIKE_ON_LINK_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000293254433",
	                 "count": {
	                     "TWOWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001753717079",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001838323910",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001183707930",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1034778664",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100000545529457",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "1436029649",
	                 "count": {
	                     "FRIEND_POST_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "520468704",
	                 "count": {
	                     "ONEWAY_MESSAGE_FLAG" : "1"
	                 }
	             },
	             {
	                 "fId" : "100001373067166",
	                 "count": {
	                     "FRIEND_COMMENT_ON_STATUS_FLAG" : "1"
	                 }
	             }
	         ]
	     };



//Convert text type flag into number type mode
function convertFlagToMode(flag){
	if(flags != null){
	   return flags[flag];	
	}
	return null;
}

function getQueryString(){
	return window.location.search.substring(1);
}

module("FriendData test");

test ("property setting test", function(){
	var flag = "MESSAGE_FLAG";
	var obj = new FriendData(flag);
	//6 assertions
	expect(6);
	equal(obj.flag, "MESSAGE_FLAG");
	equal(obj.mode, 1);
	equal(obj.data, null);
	equal(obj.colNum, 3);
	notEqual(obj.QUERY_STRING, "");
	notEqual(obj.url, null);
});

test("Faux flag", function(){
	//1 assertions
	expect(1);
	var flag = "FAUX_FLAG";
	var obj = new FriendData(flag);
	stop();
	obj.requestData(function(){
		start();
		equal(obj.data, null);
	});	
	
});

//test("invalid query string", function(){
//	var flag = "MESSAGE_FLAG";
//	var obj = new FriendData(flag);
//	obj.QUERY_STRING = "invalid_query_string";
//	
//	stop();
//	obj.requestData(function(){
//		start();
//		ok(obj.data == null);
//	});		
//});

test("request data test", function(){
	var request = new FriendData(flags["ONEWAY_MESSAGE_FLAG"] + flags["TWOWAY_MESSAGE_FLAG"]);
trace2(flags["ONEWAY_MESSAGE_FLAG"] + flags["TWOWAY_MESSAGE_FLAG"]);
	stop();	
	request.requestData(function(){
		start();
		ok(request.data != null);
	});
});

test("fill table with message data",function(){
	var flag = "MESSAGE_FLAG";
	var request = new FriendData(flags["ONEWAY_MESSAGE_FLAG"] + flags["TWOWAY_MESSAGE_FLAG"]);
	stop();	
	request.requestData(function(){
		start();
		request.addToTable();
		
		//find column number
		colNum = findColNum(flag);
		var result = false;
		$('table.rankTable tbody tr').each(function(index, element){
			if($(element).eq(colNum-1).text() != null){
				result = true;
			}
		});
		ok(result, "there must be some values in message cells");
	});
});


test("fill table with comment data",function(){
	var flag = "MY_COMMENT_ON_LINK_FLAG";
	var obj = new FriendData(flags[flag]);
	stop();	
	obj.requestData(function(){
		start();
		obj.addToTable();
		
		//find column number
		colNum = findColNum(flag);
		var result = false;
		$('table.rankTable tbody tr').each(function(index, element){
			if($(element).eq(colNum-1).text() != null){
				result = true;
			}
		});
		ok(result, "there must be some values in comment cells");
	});
});

module("all test");

test("all data", function(){
	var objs = [];
	$.each(flags, function(key, value){
		objs[key] = new FriendData(key);
		stop();
		objs[key].requestData(function(){
			start();
			objs[key].addToTable();
			
			//assertion
			colNum = findColNum(key);
			var result = false;
			$('table.rankTable tbody tr').each(function(index, element){
				if($(element).eq(colNum-1).text() != null){
					result = true;
				}
			});
			ok(result, "there must be some values in "+ key +" cells");
			
		});
	});
});